package tjs.study.notes.dotest.proxy.javassist.agent;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import tjs.study.notes.dotest.TjsStudyNotesApplication;

import java.util.List;

import static tjs.study.notes.dotest.proxy.javassist.agent.DoTestAgent.loadAgent;

/**
 * Created by Nicky.Tang on 2021/9/25 4:45 下午
 *
 * @since 02.12.10
 */
public class DoLoadAgent {
    /**
     * 命令行输入【jps -l】，可查看所有java进程
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        List<VirtualMachineDescriptor> list = VirtualMachine.list();
        for (VirtualMachineDescriptor vmd : list) {
            if (vmd.displayName().indexOf("DoTestAgent")!=-1) {
                VirtualMachine virtualMachine = VirtualMachine.attach(String.valueOf(vmd.id()));
                virtualMachine.loadAgent(TjsStudyNotesApplication.work_space + "/proxy/javassist/agent/AgentmainTraTest.jar");
                System.out.println("ok");
                virtualMachine.detach();
            }
        }
    }
}
